package com.feiwo.nonego.rpc.common.util;

import com.feiwo.nonego.rpc.common.constants.CommonConstants;

/**
 * @author feiwo 2025-08-03
 */
public class ClassUtils {

    public static String getClassName(String classFullName) {
        if (classFullName == null || !classFullName.endsWith(CommonConstants.CLASS_FILE_SUFFIX)) {
            throw new RuntimeException("classFullName is not class name");
        }
        return classFullName.substring(0, classFullName.length() - CommonConstants.CLASS_FILE_SUFFIX.length());
    }

    public static Class<?> getClassType(Object obj) {
        return switch (obj.getClass().getName()) {
            case "java.lang.Integer" -> Integer.class;
            case "java.lang.Long" -> Long.class;
            case "java.lang.Float" -> Float.class;
            case "java.lang.Double" -> Double.class;
            case "java.lang.Boolean" -> Boolean.class;
            case "java.lang.String" -> String.class;
            case "java.lang.Character" -> Character.class;
            case "java.lang.Byte" -> Byte.class;
            case "java.lang.Short" -> Short.class;
            case "java.lang.Void" -> Void.class;
            case "java.lang.Object" -> Object.class;
            case "java.lang.Class" -> Class.class;
            default -> obj.getClass();
        };
    }

}
